<?php

namespace App\Http\Middleware;

use Closure;

class EnableCrossRequest
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);
		
		// echo get_class(response($request)); // Illuminate\Http\Response
		// echo get_class($response); // Symfony\Component\HttpFoundation\Response
		// echo get_class(response()); // Illuminate\Routing\ResponseFactory
		
        // $response->header('Access-Control-Allow-Origin', config('app.allow'));
        /*
		// Call to undefined method Symfony\\Component\\HttpFoundation\\Response::header()
		$response->header('Access-Control-Allow-Origin', '*');
        $response->header('Access-Control-Allow-Headers', 'X-Requested-With, Origin, Content-Type, Cookie, Accept, Authorization');
        $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS');
        $response->header('Access-Control-Allow-Credentials', 'true');
		*/
		header('Access-Control-Allow-Origin: *');
		header('Access-Control-Allow-Headers: X-Requested-With, Origin, Content-Type, Cookie, Accept, Authorization');
		header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, OPTIONS');
		header('Access-Control-Allow-Credentials: true');

        return $response;
    }
}
